﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Edgar.Entities.MasterData
{
    public class Rulebook
    {
        public List<StepDice> StepDices { get; set; }
        public List<AttributeCharacteristics> AttributeCharacteristics { get; set; }
        public List<AttributeCost> AttributeCost { get; set; }

        public List<Race> Races { get; set; }
        public List<Discipline> Disciplines { get; set; }
        public List<Talent> Talents { get; set; }
        public Skills Skills { get; set; }
        public List<Spell> Spells { get; set; }

        public Rulebook()
        {
            StepDices = new List<StepDice>();
            AttributeCharacteristics = new List<AttributeCharacteristics>();
            Races = new List<Race>();
            Disciplines = new List<Discipline>();
            Talents = new List<Talent>();
            Skills = new Skills();
            Spells = new List<Spell>();
        }

        public Discipline GetDiscipline(string name)
        {
            if (name == null) return null;
            return Disciplines.Where(x => x.Name == name).Single();
        }

        public Race GetRace(string name)
        {

            if (name == null) return null;
            return Races.Where(x => x.Name == name).Single();
        }

        public Talent GetTalent(string name)
        {
            if (name == null) return null;
            return Talents.Where(x => x.Name == name).Single();
        }

        public string GetDice(int step)
        {
            return StepDices.Where(x => x.Step == step).Single().Dice;
        }

        public AttributeCharacteristics GetAttributeCharacteristic(int attributeEndValue)
        {
            return AttributeCharacteristics.Where(x => x.AttributeValue == attributeEndValue).Single();
        }

        public int GetAttributeCost(int attributeValue)
        {
            if (attributeValue < 1) return 0;
            return AttributeCost.Where(x => x.AttributeValue == attributeValue).Single().PurchasePoints;
        }

        public int GetRaceModificator(string raceName, string attributeName)
        {
            if (raceName == null) return 0;
            if (attributeName == "Speed")
                return GetRace(raceName).SpeedModification;
            return GetRace(raceName).AttributeModifications.Where(x => x.AttributeName == attributeName).Single().Modificator;
        }

        public int GetDeathDurability(string disciplineName)
        {
            if (disciplineName == null) return 0;
            return GetDiscipline(disciplineName).DeathDurability;
        }

        public int GetFaintDurability(string disciplineName)
        {
            if (disciplineName == null) return 0;
            return GetDiscipline(disciplineName).FaintDurability;
        }

        public List<DisciplineTalent> GetDisciplineTalents(string disciplineName)
        {
            if (disciplineName == null) return new List<DisciplineTalent>();
            return GetDiscipline(disciplineName).Talents;
        }
    }
}
